<?php
namespace app\common\model;

use think\Config;
use think\Db;
use think\Model;

class ShopProduct extends Model{


    protected $table = "jiujiu_shop_product";



    public function getShopProduct($shopId,$isPaginate=''){

        if($isPaginate){
            return Db::table('jiujiu_shop_product')
                ->field('jiujiu_product.*')
                ->join('jiujiu_product','jiujiu_product.id=jiujiu_shop_product.productId','LEFT')
                ->where('jiujiu_shop_product.shopId',$shopId)
                ->where('jiujiu_product.isDelete',0)
                ->where('jiujiu_product.isShow',1)
                ->paginate();
        }
        else{
            return Db::table('jiujiu_shop_product')
                ->field('jiujiu_product.*')
                ->join('jiujiu_product','jiujiu_product.id=jiujiu_shop_product.productId','LEFT')
                ->where('jiujiu_shop_product.shopId',$shopId)
                ->where('jiujiu_product.isDelete',0)
                ->where('jiujiu_product.isShow',1)
                ->select();
        }


    }


  public function getShopAllProduct($shopId,$isPaginate=''){

        if($isPaginate){
            return Db::table('jiujiu_shop_product')
                ->field('jiujiu_product.*')
                ->join('jiujiu_product','jiujiu_product.id=jiujiu_shop_product.productId','LEFT')
                ->where('jiujiu_shop_product.shopId',$shopId)
                ->where('jiujiu_product.isDelete',0)
                ->paginate();
        }
        else{
            return Db::table('jiujiu_shop_product')
                ->field('jiujiu_product.*')
                ->join('jiujiu_product','jiujiu_product.id=jiujiu_shop_product.productId','LEFT')
                ->where('jiujiu_shop_product.shopId',$shopId)
                ->where('jiujiu_product.isDelete',0)
                ->select();
        }


    }



    public function getShopProductBySearch($shopId,$keyword='',$isPaginate=''){

        $keyword = trim($keyword);
        if($isPaginate){
            return Db::table('jiujiu_shop_product')
                ->field('jiujiu_product.*')
                ->join('jiujiu_product','jiujiu_product.id=jiujiu_shop_product.productId','LEFT')
                ->where('jiujiu_shop_product.shopId',$shopId)
                ->where('jiujiu_product.title','like','%'.$keyword.'%')
                ->where('jiujiu_product.isDelete',0)
                ->where('jiujiu_product.isShow',1)
                ->paginate();
        }
        else{
            return Db::table('jiujiu_shop_product')
                ->field('jiujiu_product.*')
                ->join('jiujiu_product','jiujiu_product.id=jiujiu_shop_product.productId','LEFT')
                ->where('jiujiu_shop_product.shopId',$shopId)
                ->where('jiujiu_product.title','like','%'.$keyword.'%')
                ->where('jiujiu_product.isDelete',0)
                ->where('jiujiu_product.isShow',1)
                ->select();
        }


    }




}